package com.sali.asyncollection.service.impl.strategy.method3;


import com.sali.asyncollection.service.impl.strategy.method2.runable.SendMsgRunnable;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * @description:
 * @author: sali
 * @date: 2024/7/21 下午3:20.
 * @version: 1.0
 */
@Component
@Slf4j
public class AsynMethod03 {

    private ExecutorService executorService = Executors.newCachedThreadPool();

    public void execute(Long userId) throws ExecutionException, InterruptedException {
        SendMsgRunnable sendMsgRunnable = new SendMsgRunnable(userId);
        Future<?> submit1 = executorService.submit(() -> {
            log.info("赠送积分成功，用户是：{}", userId);
            return "xixi";
        });
        Future<?> submit2 = executorService.submit(() -> {
            log.info("发消息订单下单成功，用户是：{}", userId);
            return "xixi2";
        });
        System.out.println(submit1.get());
        System.out.println(submit2.get());
    }

}
